package io.renren.util;

import io.renren.entity.CheckCodeModel;
import net.jodah.expiringmap.ExpirationPolicy;
import net.jodah.expiringmap.ExpiringMap;

import java.util.concurrent.TimeUnit;

public class ExpiringMapUtil {

    public final static ExpiringMap<String, CheckCodeModel> expiringMap = ExpiringMap.builder()
            .expiration(30, TimeUnit.MINUTES)
            .expirationPolicy(ExpirationPolicy.CREATED).build();

    public static void main(String args[]) {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println(ExpiringMapUtil.expiringMap.get("zhu"));
                }
            }
        };

        Thread t1 = new Thread(runnable);
        Thread t2 = new Thread(runnable);
        t1.start();
        t2.start();
        CheckCodeModel checkCodeModel = new CheckCodeModel();
        checkCodeModel.setCheckcode("123123");
        ExpiringMapUtil.expiringMap.put("zhu", checkCodeModel);
    }
}
